package com.zhaoyd.uaademo.core;


/**
 * 通用返回实体
 * @author zhaoyd
 * @date 2020-10-31
 */
public class ResultData<T> {
    private int code;
    private String msg = "success";
    private T data;

    enum CodeEnum{
        SUCCESS(200),
        FAIL(300),
        ERROR(500),
        ;
        private int code;
        CodeEnum(int code){
            this.code = code;
        }

        public int getCode() {
            return code;
        }

        public void setCode(int code) {
            this.code = code;
        }
    }

    public static <T> ResultData success(T data){
        ResultData resultData = new ResultData();
        resultData.code = CodeEnum.SUCCESS.getCode();
        resultData.data = data;
        return resultData;
    }
    public static ResultData success(){
        return success(null);
    }
    public static ResultData fail(String msg){
        ResultData resultData = new ResultData();
        resultData.code = CodeEnum.FAIL.getCode();
        resultData.msg = msg;
        return resultData;
    }
    public static ResultData error(String msg){
        ResultData resultData = new ResultData();
        resultData.code = CodeEnum.ERROR.getCode();
        resultData.msg = msg;
        return resultData;
    }


    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }
}
